https://leetcode-cn.com/problems/reverse-integer/

class Solution {
public:
    int reverse(int x) {
        int ret = 0;
        while(abs(x)){
            if(ret > INT_MAX / 10 || ret < INT_MIN / 10) return 0;
            int digit = x % 10;
            x /= 10;
            ret = ret * 10 + digit;
        }
        if(x < 0) ret *= -1;

        return ret;
    }
};